package com.zhuifeng.orders.controller;

import com.zhuifeng.common.core.domain.R;
import com.zhuifeng.common.core.web.controller.BaseController;
import com.zhuifeng.common.core.web.domain.AjaxResult;
import com.zhuifeng.common.core.web.page.TableDataInfo;
import com.zhuifeng.common.log.annotation.Log;
import com.zhuifeng.common.log.enums.BusinessType;
import com.zhuifeng.common.security.annotation.RequiresPermissions;
import com.zhuifeng.orders.domain.Site;
import com.zhuifeng.orders.service.ISiteService;
import com.zhuifeng.system.domain.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: 周国强
 * @time: 2022/8/19 19:43
 */
@RestController
@RequestMapping("/site")
public class SiteController extends BaseController {
    @Autowired
    private ISiteService siteService;

    /**
     * 查询收货地址列表
     */
    @RequiresPermissions("site:site:list")
    @GetMapping("/list")
    public TableDataInfo list()
    {
        startPage();
        List<Site> list = siteService.selectSiteList();
        return getDataTable(list);
    }

    /**
     * 查询用户默认收货地址
     */
    @RequiresPermissions("site:site:selectUserSite")
    @Log(title = "地址", businessType = BusinessType.DELETE)
    @GetMapping("/selectUserSite")
    public R<Site> selectUserSite(){
        return this.siteService.selectUserSite();
    }
    /**
     * 获取当前登录人信息
     */
    @RequiresPermissions("site:site:selectUser")
    @GetMapping("/selectUser")
    public LoginUser selectUser(){
        return this.siteService.selectUser();
    }

    /**
     * 新增收货地址
     */
    @RequiresPermissions("orders:site:add")
    @Log(title = "收货地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Site site)
    {
        return toAjax(siteService.insertSite(site));
    }
    /**
     * 删除收货地址
     */
    @DeleteMapping("/deleteSiteId/{siteId}")
    public void deleteSiteId(@PathVariable("siteId")String siteId) {
        siteService.deleteSiteId(siteId);
    }

    @GetMapping("/selectSiteId/{siteId}")
    public Site selectSiteId(@PathVariable("siteId")String siteId) {
        Site site = siteService.selectSiteId(siteId);

        return site;
    }
    /**
     * 修改收货地址
     */
    @PutMapping("/updateSite")
    public void updateSite(@RequestBody Site site) {
        siteService.updateSite(site);
    }
    /**
     * 默认收货地址
     */
    @PutMapping("/defultSiteById/{siteId}")
    public void defultSiteById(@PathVariable("siteId")String siteId){
        siteService.defultSiteById(siteId);
    }
}
